import API from '@/api/cyindex.js';
const IndexModel = {
  namespace: 'serve',

  state: {
    // orgOptions: [],
    // orgMap: {},
    // _JJCD:{},
    // _SJLY:{},
    // _AQSJTB_SJLX:{},
    all: {},
  },

  effects: {
    *queryDict({ payload }, { call, put }) {
      const res = yield call(API.dictItemList, payload);
      if (res?.t) {
        const all = res.t.map((x) => {
          return {
            label: x.dictItemName,
            value: x.dictItemType,
            type: x.dictCode,
          };
        });
        yield put({
          type: 'saveDict',
          payload: {
            all,
          },
        });
      }
    },
  },
  reducers: {
    saveDict(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
    // 启用 immer 之后
    // save(state, action) {
    //   state.name = action.payload;
    // },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        if (pathname === '/networkInfor/safetyIncidentNotice') {
          dispatch({
            type: 'queryDict',
            payload: {},
          });
        }
      });
    },
  },
};

export default IndexModel;
